﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dtos;
using IBLL;
using IDAL;
using Model;

namespace BLL
{
    public class TeachersGrandesBll:ITeachersGradesBll
    {
        private ITeachersGradesDal _TG;
        public TeachersGrandesBll(ITeachersGradesDal TG) 
        { 
          _TG = TG;
        }
        public async Task<int> AddTeachersGradesAsync(Guid gradesId, Guid teachersId)
        {
            return await _TG.AddAsync(new Model.TeachersGrades
            {
                gradesId = gradesId,
                teachersId = teachersId
            });
        }

        public async Task<int> DeleteTeachersGradesAsync(Guid id)
        {
            var data = await _TG.GetIdAll(id);
            return data != null ? await _TG.DeleteAsync(data) : 0;
        }

        public async Task<int> EditTeachersGradesAsync(Guid id, Guid gradesId, Guid teachersId)
        {
            var data = await _TG.GetIdAll(id);
            if (data == null)
                return 0;
            data.gradesId = gradesId;
            data.teachersId = teachersId;
            data.UpdateTime = DateTime.Now;
            return await _TG.UpdateAsync(data);
        }

        public async Task<List<TeachersGradesDtos>> getAllTeachersGrades()
        {
            var data = await _TG.GetAll();
            return data.Select(d => new TeachersGradesDtos
            {
                Id = d.Id,
                gradesId = d.gradesId,
                teachersId = d.teachersId,
                UpdateTime = DateTime.Now
            }).OrderByDescending(d => d.UpdateTime).ToList();
        }

        public async Task<TeachersGradesDtos> GetTeachersGradesDtoAsync(Guid id)
        {
            throw new NotImplementedException();
        }
    }
}
